﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ViVa.ActiveDirectory;

namespace ViVa_Portal.Controllers
{
    public class HomeController : Controller
    {
        #region Index
        public ActionResult Index()
        {
            PermissionService.setPermission();
            if ((bool)Session["isGuest"]) { return RedirectToAction("SelfService"); }
            if ((bool)Session["isHelpdesk"]) { return RedirectToAction("ZoekADUser", "ADUser"); }
            if ((bool)Session["isAdmin"]) { return RedirectToAction("Index", "Admin"); }

            return RedirectToAction("SelfService");
        }
        #endregion

        #region SelfService
        [HttpGet]
        public ViewResult SelfService()
        {
            return View(ADService.GetUserBySamAccountName(PermissionService.userName()));
        }

        [HttpPost]
        public ViewResult SelfService(ADEntry userObj)
        {
            ADService.Save(userObj);
            userObj = ADService.GetUserBySamAccountName(userObj.SamAccountName);
            Logging.Log(userObj.SamAccountName, 0, userObj.Name + " heeft zijn/haar gegevens aangepast");
            return View(ADService.GetUserBySamAccountName(PermissionService.userName()));
        }
        #endregion


        #region Geen rechten
        public ViewResult GeenRechten()
        {
            return View();
        }
        #endregion
    }
  
}
